import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

df = pd.read_excel("zhongjiang.xlsx")

df["draw_date"] = pd.to_datetime(df["开奖日期"])
df["total_sales"] = pd.to_numeric(df["总销售金额（元）"], errors='coerce')/3
df_grouped = df.groupby("draw_date")["total_sales"].sum().reset_index()
df_grouped = df_grouped.sort_values("draw_date")

plt.figure(figsize=(12, 6))
plt.plot(df_grouped["draw_date"], df_grouped["total_sales"], marker='o', color='blue', label='Sales')
plt.xlabel("Draw Date")
plt.ylabel("Total Sales (Yuan)")
plt.title("Sales Over Time")
plt.grid(True)
plt.xticks(rotation=45)
plt.legend()
plt.tight_layout()
plt.show()

df_grouped["days"] = (df_grouped["draw_date"] - df_grouped["draw_date"].min()).dt.days
X = df_grouped[["days"]]
y = df_grouped["total_sales"]

model = LinearRegression()
model.fit(X, y)

next_day = df_grouped["days"].max() + 1
predicted = model.predict([[next_day]])

print(f"预测下一期的销售额为：{predicted[0]:,.2f} 元")